package com.drore.logapp.http.converter;

import android.util.Log;

import com.google.gson.Gson;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;


/**
 * Created by xiangl
 * on 2018/4/24 0024 下午 3:02
 * description :
 */

public class StringConverterFactory extends Converter.Factory {
    /**
     * +     * Create an instance using a default {@link Gson} instance for conversion. Encoding to JSON and
     * +     * decoding from JSON (when no charset is specified by a header) will use UTF-8.
     * +
     */
    public static StringConverterFactory create() {
        return create(new String());
    }

    /**
     * Create an instance using {@code gson} for conversion. Encoding to JSON and
     * decoding from JSON (when no charset is specified by a header) will use UTF-8.
     */
    public static StringConverterFactory create(String string) {
        return new StringConverterFactory(string);
    }

    private final String string;

    private StringConverterFactory(String string) {
        if (string == null) {
            Log.e("StringConverterFactory","string  is  null");
            string = "null";
        }
        this.string = string;
    }

    @Override
    public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations,
                                                            Retrofit retrofit) {
        return new StringResponseBodyConverter<>();
    }

}
